<template>
<el-carousel :interval="4000" type="card" height="300px" style="margin: 20px">
<el-carousel-item v-for="item in data.formData" :key="item">
  <img :src="item.img" alt="" style="width: 100%; cursor: pointer; height: 100%;border-radius: 5px;"/>
</el-carousel-item>
</el-carousel>
<div style="width: 80%;margin: 20px auto">
<div style="font-size: 20px; font-weight: bold; border-left: 5px solid #2fbd67;padding-left: 10px;height: 30px;line-height: 30px">旅游攻略</div>
<div style="margin-top: 20px">
  <el-row :gutter="20">
    <el-col v-for="item in data.introductionData" :span="6" style="margin-bottom: 10px">
      <img @click="navTo('/front/introductionDeta?id='+item.id)" :src="item.img" alt="" style="width: 100%; height: 310px;border-radius: 5px; cursor: pointer;">
      <div  style="font-size: 16px; cursor: pointer; font-weight: bold;margin-top: 10px;">{{item.title}}</div>
      <div style="display: flex;align-items: center; margin-top: 10px;grid-gap: 10px;">
        <img :src="item.userAvatar" alt="" style="width: 30px; height: 30px;border-radius: 50%;cursor: pointer;">
        <div style="font-size: 10px;">{{item.userName}}</div>
        <div style="color: #666666">{{item.time}}</div>
      </div>
    </el-col>
  </el-row>
</div>
</div>

<div style="width: 80%;margin: 20px auto">
<div style="font-size: 20px; font-weight: bold; border-left: 5px solid #2fbd67;padding-left: 10px;height: 30px;line-height: 30px">旅游攻略</div>
<div style="margin-top: 20px">
  <div  v-for="item in data.introductionData" style="margin-bottom: 10px;display: flex;height: 300px">
    <div style="flex: 1;background-color: #2fbd67">
      <img @click="navTo('/front/introductionDeta?id='+item.id)" :src="item.img" alt="" style="width: 100%; cursor: pointer; height: 100%;border-radius: 5px;"/>
    </div>
    <div style="flex: 3;margin-left: 10px;">
      <div style="font-size: 20px; font-weight: bold;">{{item.title}}</div>
      <div class="line4" style="margin-top: 10px; font-size: 15px; color: #666666; line-height: 25px;height: 100px;text-align: justify" >{{ item.description }}</div>
      <div style="display: flex;align-items: center; margin-top: 10px;grid-gap: 10px;">
        <img  :src="item.userAvatar" alt="" style="width: 30px; height: 30px;border-radius: 50%;">
        <div style="font-size: 10px;">{{item.userName}}</div>
        <div style="color: #666666">{{item.time}}</div>
      </div>
    </div>
  </div>
</div>
</div>
</template>

<script setup>
import {reactive} from "vue";
import request from "@/utils/request.js";
import {ElMessage} from "element-plus";

const data  = reactive({
  user:JSON.parse(localStorage.getItem('code_user') || '{}'),
  introductionData:[],
  formData:[],
})

const introduction = () =>{
  request.get('/introduction/selectAll').then(res =>{
    if(res.code === '200'){
      data.introductionData = res.data.slice(0,4)
    } else {
      ElMessage.error(res.msg)
    }
  })
}
introduction()

const navTo = (url) =>{
  location.href = url
}

const loadUser = () =>{
  request.get('/lunbo/selectAll').then(res =>{
    if(res.code === '200'){
      data.formData = res.data
    } else {
      ElMessage.error(res.msg)
    }
  })
}
loadUser()
</script>

<style scoped>
.line4 {
  word-break: break-all;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;    /*只显示4行*/
  overflow: hidden;
}
.el-carousel__item h3 {
  color: #475669;
  opacity: 0.75;
  line-height: 200px;
  margin: 0;
  text-align: center;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}
</style>